import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/search_bean.dart';
import 'package:app/src/manager/ywx_manager.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/http/bean/ywx_limit.dart';
import 'package:app/src/ui/route/todo/todo_review_list.dart';
import 'package:app/src/ui/route/works/public/review_list.dart';

///待办事项
class TodoRoute extends StatefulWidget {
  YwxItem? item = YwxIdManager.getDefaultYwxItem();

  @override
  _TodoState createState() => _TodoState();
}

class _TodoState extends State<TodoRoute>{
  _TodoPresenter presenter = _TodoPresenter();

  @override
  void initState() {
    super.initState();
    if (presenter.searchInfo == null) {
      presenter.searchInfo = SearchInfo(widget.item)
        ..isShowContractCode = true //合同编号
        ..isShowOutCode = true //合同外部编号
        ..isShowProjectName = true //项目名称
        ..isShowCustomerName = true //客户名称
        ..isShowMerchandiserName = true //客服经理
        ..isShowSalesmanName = true; //销售经理
    }
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    // print("=================销毁");
  }

  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
    // print("=================deactivate()");
  }

  @override
  void activate() {
    // TODO: implement activate
    super.activate();
    // print("=================activate()");
  }



  @override
  void reassemble() {
    // TODO: implement reassemble
    super.reassemble();
    //print("=================reassemble()");
  }

  @override
  Widget build(BuildContext context) {
    //print("=================构建");
    px.init(context);
    var scaffold = Scaffold(
      backgroundColor: AppColors.backgroundColorWithWhite,
      appBar: AppBar(
        backgroundColor: AppColors.backgroundColorWithWhite,
        elevation: 0,
        leading: AppUi.getBack(context, () {
          return false;
        }),
        leadingWidth: 33,
        titleSpacing: 0,
        title: AppUi.getTitle(AppStrings.of(context).todo),
      ),
      body: _body(context),
    );
    return WillPopScope(
      child: scaffold,
      onWillPop: () async {
        return true; //true 不屏蔽返回键
      },
    );
  }

  Widget _body(BuildContext context) {
    return StatefulBuilder(
        builder: (BuildContext context, StateSetter setState) {
      presenter.setStateBody = setState;
      List<Widget> children = [];
      //搜索条件
      // var searchLayout =
      //     AppUi.getSearchLayout(context, presenter.searchInfo!, () {
      //   presenter.setStateBody?.call(() {});
      // });
      // children.add(searchLayout);
      //审核列表
      var reviewList = TodoReviewList(widget?.item, true);
      children.add(Expanded(child: reviewList));
      return Column(
        children: children,
      );
    });
  }
}

class _TodoPresenter {
  ///搜索条件
  SearchInfo? searchInfo = null;

  ///body视图状态
  StateSetter? setStateBody;
}
